//
//  StateTableViewCell.m
//  uniquelove
//
//  Created by ibokan on 14-12-17.
//  Copyright (c) 2014年 ibokan. All rights reserved.
//

#import "StateTableViewCell.h"
#import "StateFrame.h"
#import "StateModel.h"

@interface StateTableViewCell()

//时间
@property (strong, nonatomic) UILabel *timeView;
//头像
@property (strong, nonatomic) UIImageView *iconView;

//昵称
@property (strong, nonatomic) UILabel *nameView;

//正文
@property (strong, nonatomic) UIButton *textView;


@end


@implementation StateTableViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"message";
    StateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[StateTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 子控件的创建和初始化
        
        //时间
        self.timeView = [UILabel new];
        self.timeView.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.timeView];
        
        //头像
        UIImageView *imageView = [[UIImageView alloc]init];
        [self.contentView addSubview:imageView];
        self.iconView = imageView;
        
        //昵称
        self.nameView = [UILabel new];
        self.nameView.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:self.nameView];
        
        //正文
        self.textView = [UIButton new];
        [self.textView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.textView.titleLabel.numberOfLines = 0;
        
//        self.textView.titleLabel.textAlignment = NSTextAlignmentLeft;
        
        self.textView.titleLabel.font = TextFont;
//        self.textView.contentEdgeInsets = UIEdgeInsetsMake(TextPadding, TextPadding, TextPadding, TextPadding);

        [self.contentView addSubview:self.textView];
    }
    return self;
}

-(void)setStateFrame:(StateFrame *)stateFrame{
    _stateFrame = stateFrame;
    StateModel *stateModel = stateFrame.stateModel;
    
    //时间
    NSString *timeStr = stateModel.time;
    self.timeView.text = timeStr;
    self.timeView.frame = stateFrame.timeF;
    
    //头像
    if (stateModel.type == StateTypeMe) {
        NSData *data = [[NSUserDefaults standardUserDefaults]objectForKey:@"imageData"];
        UIImage *image = [UIImage imageWithData:data];
        self.iconView.image = image;
        
        //昵称
        self.nameView.text = @"木维希";
    }else{
        self.iconView.image = [UIImage imageNamed:@"share_weibo.png"];
        //昵称
        self.nameView.text = @"我最爱的人";
    }
   
    self.nameView.frame = stateFrame.nameF;
    
    self.iconView.frame = stateFrame.iconF;
    
    
    
    //正文
    [self.textView setTitle:stateModel.text forState:UIControlStateNormal];
    self.textView.frame = stateFrame.textF;
    
    // 正文的背景
    if (stateModel.type == StateTypeMe) { // 自己发的
        self.textView.backgroundColor = [UIColor grayColor];
    } else { // 别人发的,白色
        self.textView.backgroundColor = [UIColor lightGrayColor];
    }
    
}



@end
